package com.hse.console;

import com.hse.network.ICoordinator;
import com.hse.network.ICoordinatorClient;
import com.hse.network.NetworkFactory;
import com.hse.network.exceptions.NetworkException;

/**
 * Created by IntelliJ IDEA.
 * User: kate
 * Date: 30.05.2009
 * Time: 17:06:15
 * To change this template use File | Settings | File Templates.
 */
public class Server {
    private final static short PAN_ID = (short) 12345;
    private final static String PORT_NUMBER = "COM7";
    private final static Long MAC_ADDRESS = 1L;

    public static void main(String[] args) throws InstantiationException, NetworkException {
        System.out.println("Sample program for testing network layer: server version");
        System.out.println("Creating coordinator...");
        ICoordinator coordinator = NetworkFactory.createCoordinator(PORT_NUMBER, MAC_ADDRESS);
        System.out.println("Coordinator was created successfuly");
        System.out.println("Creating network...");
        coordinator.createNetwork(PAN_ID);
        System.out.println("Network was created successfuly");
        System.out.println("Accepting client....");
        ICoordinatorClient client = coordinator.accept();
        System.out.println("Client accepted successfuly");
        System.out.println("Recevind data...");
        byte[] data = client.recv();
        System.out.println("Recved data from client: " + new String(data));
        System.out.println("Sending data to client...");
        client.send("Hello from server!".getBytes());
        System.out.println("Data sent successfully");
        System.out.println("Closing endDevice...");
        coordinator.close();
        System.out.println("Everything worked just fine!");
    }
}
